package ahblue.cn.tanzi.ui.person;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import java.math.BigDecimal;

import ahblue.cn.tanzi.R;
import ahblue.cn.tanzi.jmessage.im.util.DialogCreator;
import ahblue.cn.tanzi.jmessage.im.util.ToastUtil;
import ahblue.cn.tanzi.model.user.CodeModel;
import ahblue.cn.tanzi.model.user.LoginResultModel;
import ahblue.cn.tanzi.ui.base.BaseActivity;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 充值界面
 * Created by fengdongfei on 2018/12/1.
 */

public class GetMoneyActivity extends BaseActivity {
    @BindView(R.id.etmoney)
    EditText etmoney;
    private Dialog mDialog;


    public static void into(Activity activity) {
        activity.startActivity(new Intent(activity, GetMoneyActivity.class));
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_get_money);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.btn_back, R.id.tvok})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_back:
                finish();
                break;
            case R.id.tvok:
                String bankCard = etmoney.getText().toString();
                if (TextUtils.isEmpty(bankCard)) {
                    ToastUtil.shortToast(this, "请输入金额");
                    return;
                }
                if(bankCard.startsWith(".")){
                    ToastUtil.shortToast(this, "请输入正确的数字");
                    return;
                }
                if (new BigDecimal(bankCard).compareTo(new BigDecimal("0")) <= 0){
                    ToastUtil.shortToast(this, "请输入大于0的数字");
                    return;
                }
                mDialog = DialogCreator.createLoadingDialog(this, "正在提现");
                mDialog.show();
                CodeModel.getPayMoney(GetMoneyActivity.this, bankCard, LoginResultModel.getToken(this), new CodeModel.VertifyListener() {

                    @Override
                    public void conver(boolean orderSn) {
                        mDialog.dismiss();
                        finish();
                    }
                });
                break;
        }
    }
}
